﻿#region Using Directives
using System;
using System.Data;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using Karasoft.Web.Data;
#endregion

namespace Karasoft.Web.UI
{
	/// <summary>
	/// Provides helper methods for use in web pages and controls.
	/// </summary>
	public partial class FormUtil
	{
		//private static readonly String ControlCacheKey = "ControlCache";

        /// <summary>
        /// Loads an instance of an IBindableTemplate from the specified path.
        /// </summary>
        /// <param name="control">The TemplateControl which will perform the load.</param>
        /// <param name="path">The path to the template to load.</param>
        /// <returns>An instance of IBindableTemplate found at the specified path.</returns>
        /// <remarks>
        /// Adapted from an article written by James Crowley, which can be found at:
        /// http://www.developerfusion.co.uk/show/4721/
        /// </remarks>
        public static IBindableTemplate LoadBindableTemplate(TemplateControl control, String path)
        {
            Control container = control.LoadControl(path);
            FormView formView = container.Controls[0] as FormView;

            if (formView == null)
            {
                throw new Exception("Required FormView control not found as the first child of specified template");
            }

            return (IBindableTemplate)formView.ItemTemplate;
        }


	}
	
	#region Enums
	/// <summary>
	/// used to determine the persistence method
	/// </summary>
	public enum PersistenceMethod
	{
        /// <summary>
        /// no persistents
        /// </summary>
        None = 0,
		/// session state will be used
		Session = 1,
		/// client cookie will be used
		Cookie = 2,
		/// a persistent client cookie will be used
		PersistentCookie = 3,
	}
	#endregion
}